<?php

    require_once 'HtmlHelper.php';

    $this->setVar('pageTitle', 'Form example');

    // In this case we've extended the Form. You could also create the form on
    // the fly:
    // $form = new SimpleForm();
    // $form->addElement('myElement') etc.

    $simpleFormExample = new ExampleSimpleForm;

    if ($request->isPost()) {
        // Setting the data to the form will apply any filters specified in the
        // form.
        $simpleFormExample->setData($request->getPost());

        // As the form isn't validated before, a call to the isValid method will
        // automaticly validate the form.
        if ($simpleFormExample->isValid()) {
            $formMessage = 'The form example is valid.';
        } else {
            $formMessage = 'The form example is NOT valid.';
        }


    }
?>
<h1>SimpleForm example</h1>
<p>Check out the source code in src/views/examples/simpleform.php.</p>
<form action="" method="post">
    <fieldset>
        <legend>Example form</legend>
        <?php if (isset($formMessage)): ?><p><strong><?php echo $formMessage; ?></strong></p><?php endif; ?>
        <div>
            <label for="validated-data">Validated data (uses the "required" validator)</label>
            <input type="text" id="validated-data" name="validatedData" value="<?php echo $simpleFormExample->validatedData; ?>" />
            <?php HtmlHelper::renderUL($simpleFormExample->getValidationMessages('validatedData'), 'validation-messages', null, null, 'Validated data '); ?>
        </div>
        <div>
            <label for="filtered-data">Filtered data (uses the "stripTags" filter - will strip HTML tags)</label>
            <input type="text" id="filtered-data" name="filteredData" value="<?php echo $simpleFormExample->filteredData; ?>" />
        </div>
        <input type="submit" value="Submit form" />
    </fieldset>
</form>